<?php
	$weeknr=date('Y').date('W');


	$SITE_MIDDLE .=  "<center><font size=6>
		<a href='javascript:ShowRadioWindow()'>".GetLangString($lang,"txt_listennow") ."</a><br>
		<a href='http://blaatschaap.be:8200/stream.ogg.m3u'>".GetLangString($lang,"txt_listennow2") ."</a><br>
	</font>
	</center>";


	$infotxt .= "<a href=\"index.php?do=radio&view=djs\">" . GetLangString($lang,"txt_djs") . "</a><br> ";
	$infotxt .= "<a href=\"index.php?do=radio&view=shows\">" . GetLangString($lang,"txt_radioshows") . "</a><br> ";	
	$infotxt .= "<a href=\"index.php?do=radio&view=req\">" . GetLangString($lang,"txt_radiorequest") . "</a><br> ";	
//	$infotxt .= "<a href=\"index.php?do=radio&view=gb\">" . GetLangString($lang,"txt_radiogb") . "</a><br> ";	


	$SITE_RIGHT .= FormatSmallElement(GetLangString($lang,"txt_radio"),$infotxt);




if($_REQUEST['popup']) {
	$ISTEXT=0;
	/*
	$code = "<html><head><title>Radio</title></head><body> 
		<object width=\"180\" height=\"70\">
		<param name=\"movie\" value=\"3rdparty/minicaster/minicaster.swf\">
		<embed width=\"180\" height=\"70\" src=\"3rdparty/minicaster/minicaster.swf\">
		</embed>
		</object>";
	*/
	echo ("<html><head><title>Radio</title></head><body> 
		<iframe src='http://www.jcraft.com/jorbis/player/JOrbisPlayer.php?play=http://blaatschaap.be:8200/stream.ogg' 
		width='620' height='150'></iframe></body></html>");
} else 

if ($_REQUEST['dj']) {
	$dj_id = escapestr($_REQUEST['dj']);
	$query        = "SELECT * from radio_dj where id='" . $dj_id ."'";
	$result = mysql_query($query);
	if (mysql_num_rows($result)){ 
		$dj_info = mysql_fetch_array($result);
		$dj_name = $dj_info['name'];

		$dj_text = "<center><table border=\"0\" width=\"75%\"><tr><td valign=\"top\">".$dj_info['text']. 
								"</td><td width=\"300\" valign=\"top\"><img src=\"index.php?do=getphoto&size=300&square=1&id=".
									$dj_info['photo']."\"></td></tr></table></center>";

		$SITE_MIDDLE .= FormatElement ($dj_name, bb2html($dj_text)) ; 
	} else {
	//invalid dj id	
	}
} else

if ($_REQUEST['view']=="djs") {
	$query        = "SELECT * from radio_dj";
	$result = mysql_query($query);
//	$img = "images/sheep.png";

	
	if (mysql_num_rows($result)){ 
		while ($dj_info = mysql_fetch_assoc($result)){
	$img = "/index.php?do=getphoto&id=".$dj_info['photo']."&size=150&square=1";			
  if ($dj_info['name'])
			$djs.=	"<div class=\"djthumb\">
											<a href=\"/index.php?do=radio&dj=".$dj_info['id']."\">												
											".$dj_info['name']."</a><br><br><img src=\"$img\" alt=\"$TXT_NOIMG\" 
												width=\"150\" height=\"150\"></div>";


		}
	$SITE_MIDDLE .= FormatElement ( GetLangString($lang,"txt_djs"),$djs);		
	} else {
	//invalid dj id	
	}
}  else
if ($_REQUEST['view']=="gb") {
	if ($_POST['text']) {
		$gbaddtext = escapestr($_POST['text']);
		if ($id) {
			$userid=$id; 
			$security = ScurityCheck($gbaddtext);
		} else {
			$userid=0;		
			$security = ExtraSecurityCheck($gbaddtext);
		}
		text2html($gbaddtext);
		if ($security) {
			$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_error"),GetLangString($lang,"msg_baddata"));
		} else {
			$time=time();
			$query	=	"INSERT INTO `radio_gb` (`text`,`userid`,`ip`,`agent`,`time`) values ('$gbaddtext','$userid','$ip','$AGENT','$time')";	
			$result = mysql_query ($query); 
			$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_radiogb"),GetLangString($lang,"msg_messagesent"));
		}
	}
	$query	=	"SELECT * from radio_gb";
	$result = mysql_query ($query); 
	while (	$gbentry = mysql_fetch_array($result)) {
		$entrytime = date("d-m-Y H:i:s",$gbentry['time']);
		$entrytext = $gbentry['text'];
		$entries = "<i>$entrytime</i><br>$entrytext<hr>$entries";
	}
	$SITE_MIDDLE .=	FormatElement ( GetLangString ( $lang , "txt_radiogb" ) , bb2html($entries) ) ; 

	$addentry = "
	<form action=\"/index.php?do=radio&view=gb\" method=\"post\">".
	FormatSmallElement ( GetLangString ( $lang, "txt_comment" ) , "
	<textarea rows=\"5\" name=\"text\"></textarea>
	<input type=\"submit\" value=\"".GetLangString ( $lang, "txt_send" ).
	"\"></form>");
	
	$SITE_MIDDLE .=FormatElement ( GetLangString ( $lang , "txt_radiogb" ) , $addentry ) ; 


} else
if ($_REQUEST['doreq']) {

	$from 		= escapestr ( $_REQUEST['from'] ) ;
	$to 			= escapestr ( $_REQUEST['to'] ) ;
	$artist 	= escapestr ( $_REQUEST['artist'] ) ;
	$song 		= escapestr ( $_REQUEST['song'] ) ;
	$text 		= escapestr ( $_REQUEST['text'] ) ;

	$agent 	 	= escapestr ( $AGENT ) ; 
	$ip 			= $_SERVER['REMOTE_ADDR'];
	$time = time();
	if ($id) $userid=$id; else $userid=0;
	$query = "insert into `radio_request` 	(`userid`,  `from`,`to`,  `artist`,`song`,  `text`, `time`,  `agent`,`ip`) values 
	    					('$userid','$from','$to','$artist','$song','$text','$time', '$agent','$ip')";  
	$result = mysql_query ($query) ;
	if ($result) {
	$SITE_MIDDLE .= FormatElement( GetLangString ($lang, "txt_radiorequest") , GetLangString ($lang, "msg_requestsent"));	
	} else {
	$SITE_MIDDLE .= FormatElement( GetLangString ($lang, "txt_error") , GetLangString ($lang, "msg_dberror"));  	
		$SITE_MIDDLE .= $query;
	}

} else
if ($_REQUEST['view']=="req") {
	
	$reqform = "<form action=\"/index.php?do=radio\" method=\"post\">".			
							FormatElement( GetLangString ($lang , "txt_from") ,"
							<input type=\"text\" value=\"$name\" name=\"from\">") . 
							FormatElement( GetLangString ($lang , "txt_to") ,"
							<input type=\"text\"  name=\"to\">") .
							FormatElement( GetLangString ($lang , "txt_artist") ,"
							<input type=\"text\" name=\"artist\">") .
							FormatElement( GetLangString ($lang , "txt_song") ,"
							<input type=\"text\" name=\"song\">") .
							FormatElement( GetLangString ($lang , "txt_comment") ,"
							<textarea name=\"text\" rows=\"5\"></textarea>
							<input type=\"submit\" name=\"doreq\"value=".
							GetLangString($lang, "txt_radiorequest")
							."></form>");

	$SITE_MIDDLE .= FormatElement ( GetLangString ($lang , "txt_radiorequest") , $reqform);
} else
if ($_REQUEST['view']=="shows") {
	$query        = "SELECT * from radio_show ORDER BY `day`";
	$result = mysql_query($query);
	if (mysql_num_rows($result)){ 
			$shows.=	"<center><table width=\"80%\" border=\"0\">
									<tr>
										<td width=\"25%\">".GetLangString($lang,"txt_day") ."</td> 
										<td width=\"25%\">".GetLangString($lang,"txt_start") ."</td> 
										<td width=\"25%\">".GetLangString($lang,"txt_stop") ."</td> 
										<td width=\"25%\">".GetLangString($lang,"txt_dj") ."</td> 
									</tr>";


		while ($show_info = mysql_fetch_assoc($result)){
			
			$query2 	= "select `name` from `radio_dj` where `id`=".$show_info['dj'];
			$result2 	= mysql_query ($query2) ; 
			$dj_name 	= mysql_result($result2,0);
			$dj_name  = "<a href=\"/index.php?do=radio&dj=".$show_info['dj']."\">$dj_name</a>";		
			$day = GetLangString ($lang, "txt_day".$show_info['day']);
			$shows.=	"<tr>
									<td>$day</td>
									<td>".$show_info['start'] ."</td>
									<td>".$show_info['stop'] ."</td>
									<td>$dj_name</td>
								</tr>"; 
		}
	$shows .= "</table></center>";
	$SITE_MIDDLE .= FormatElement ( GetLangString($lang,"txt_radioshows"),$shows);		
	} else {
	//invalid dj id	
	}
} else 

if ($_REQUEST['vote']) {
	if ($_COOKIE['voted'] == $weeknr) {
		$SITE_MIDDLE .= FormatElement( GetLangString ( $lang, "txt_vote"), GetLangString ( $lang, "msg_alreadyvoted")); 
	} else {
		setcookie("voted",$weeknr);
		if ($_REQUEST['vote']=="+") {
			$query = "UPDATE radio_weekly set votes=votes+1 where week = $weeknr";
			$result = mysql_query($query);
			$query = "UPDATE radio_weekly set score=score+1 where week = $weeknr";
			$result = mysql_query($query);
		} else {
			$query = "UPDATE radio_weekly set votes=votes+1 where week = $weeknr";
			$result = mysql_query($query);
			$query = "UPDATE radio_weekly set score=score-1 where week = $weeknr";
			$result = mysql_query($query);
		}
		$SITE_MIDDLE .= FormatElement( GetLangString ( $lang, "txt_vote"), GetLangString ( $lang, "msg_voted")); 
	} 
}
else 
{


//$SITE_MIDDLE .= FormatElement ( GetLangString ( $lang , "txt_radiowelcome" ), GetLangString ( $lang , "msg_radiowelcome" )) ; 


	$query = "Select * from `radio_news` where `lang`='$lang' order by `time` desc limit 3";
	$result 		=	 mysql_query($query);
	if (mysql_num_rows($result)) {
		while ($news = mysql_fetch_assoc($result)){
			$time = str_ireplace("%datetime%",date("d-m-Y H:i:s",$news['time']),GetLangString($lang,"txt_newsadded"));
			$radionews .= FormatSmallElement( $time , $news['text'] );
		}
	} else {
		$radionews = 	GetLangString($lang,"txt_nonews");
	}
	$SITE_MIDDLE .= FormatElement( GetLangString ($lang, "txt_news") , bb2html($radionews) ) ;


include ("todayshow.php");

		//

//


$query 			= "SELECT * from radio_weekly where week=" . $weeknr ;
$result 		= mysql_query($query);
$weekly	 		= mysql_fetch_array($result);
if ($weekly) {
	$query2 		= "select `name` from `radio_dj` where `id`=".$weekly['dj'];
	$result2 		= mysql_query ($query2) ; 
	$weekly_dj 	= mysql_result($result2,0);

	$klapper.=	"<center><table width=\"80%\" border=\"0\">
							<tr>
								<td width=\"20%\">".GetLangString($lang,"txt_dj") ."</td> 
								<td width=\"20%\">".GetLangString($lang,"txt_artist") ."</td> 
								<td width=\"20%\">".GetLangString($lang,"txt_song") ."</td> 
								<td width=\"20%\">".GetLangString($lang,"txt_votes") ."</td> 
								<td width=\"20%\">".GetLangString($lang,"txt_score") ."</td> 
							</tr>
							<tr>
								<td width=\"20%\">". $weekly_dj 			."</td> 
								<td width=\"20%\">". $weekly['artist']	."</td> 
								<td width=\"20%\">". $weekly['song']  ."</td> 
								<td width=\"20%\">". $weekly['votes']  ."</td> 
								<td width=\"20%\">". $weekly['score']  ."</td> 
							</tr>
						</table>
					</center>
	";


	$vote			.= "<div class=\"vote\"><center><form method=\"POST\" ACTION=\"/index.php?do=radio\">"; 
	$vote 		.= "<input value=\"-\" name = \"vote\" type=\"submit\"><input value=\"+\" name = \"vote\" type=\"submit\"></form></center></div>"  ;

	$klapper  = FormatSmallElement( GetLangString ($lang, "txt_weeklyresult") , "$klapper");
	$klapper .= FormatSmallElement( GetLangString ($lang, "txt_vote") , $vote);

	$SITE_MIDDLE .= FormatElement ( GetLangString ( $lang , "txt_weeklysong" ), $klapper) ; 


	}




}









?>
